package ru.nsu.effel.persistence;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.transform.Transformers;

public class TariffManager {
	private static TariffManager instance = null;
	
	public static TariffManager getInstance() {
		if (null == instance) {
			instance = new TariffManager();
		}
		return instance;
	}
	
	private TariffManager() {
		
	}
	
	public List<Tariff> getAllTariffs() {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		List<Tariff> tariffs = session.createCriteria(Tariff.class).addOrder(Order.asc("id")).setCacheable(false).list();
		session.getTransaction().commit();
		session.close();
		return tariffs;
	}
	
	public Tariff getById(int id) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		Tariff tariff = (Tariff)session.get(Tariff.class, id);
		session.getTransaction().commit();
		session.close();
		return tariff;
	}
}
